<?php
class Router
{
	public $param = array();
	
	public function __construct($is_sys = true) 
	{
		$run = $is_sys ? $GLOBALS['sys_run'] : $GLOBALS[APP_NAME . '_run'];
		if ( ! isset($run)) Message::error('$GLOBALS');
		$router = $run['router'];
		$pathinfo = isset($_SERVER['PATH_INFO']) && ! empty($_SERVER['PATH_INFO']) ? Unit::safe($_SERVER['PATH_INFO']) : header('Location:' . $run['default_mod']);
		if ($router && isset($pathinfo) && ! empty($pathinfo)) {
			$this->param = explode('/', $pathinfo);
			array_shift($this->param);
		}
		if ( ! empty($_GET)) {
			$this->param = array_merge($_GET, $this->param);
		}
	}
	
	public static function init()
	{
		$router = new self();
		return $router;
	}
	
	// 根据索引获取url信息
	public function getParam($key = 0)
	{
		$res = null;
		if (isset($this->param[$key])) {
			$res = $this->param[$key];
		}
		return $res;
	}
	
}